<table cellspacing="0" cellpadding="0" width="100%" class="sTable" style="font-size: 14px; color: black;">
    <thead>
        <tr style="border-bottom: 3px solid #dbdbdb;">
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;width: 15%;">Date</td>
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;">Code</td>
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;">Details</td>
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;">Invoice</td>
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;">Collection</td>
            <td style="color: #4D79B3;font-size: 15px;font-weight: bold;">Balance</td>
        </tr>
    </thead>
    <tbody>
        <?php $amount = $oldBalance ; ?>
        <tr style="border-bottom: 3px solid #dbdbdb;">
            <td align="center" colspan="5" style="padding: 0px 0px;color: #9C9C9C;font-weight:bold;">Old Balance</td>
            <td align="center"><?= number_format(-1*$amount, 2)?></td>
        </tr>
        <?php foreach ($result as $key => $value) :?>
        <tr style="border-bottom: 3px solid #dbdbdb;">
            <td><?= date('d-m-Y', strtotime($value['date']));?></td>
            <td align="center"><a class="underline" href="javascript:void(0);" onClick="<?= ($value['amount'] < 0)?'editInvoice(false,false,'.$value['code'].');':'editCollection(false,false,'.$value['code'].');'?>"><?= $value['code'] ?></a></td>
            <td align="center" style="padding: 0px 0px;">
                <?php if(isset($value['InvoiceProduct'])): ?>
                        <table cellspacing="0" cellpadding="0" width="100%" class="sTable">
                        <thead>
                            <tr>
                                <td style="font-size: 13px;color: #997C31;font-weight: bold;padding: 1px 18;width: 30%;">Product</td>
                                <td style="font-size: 13px;color: #997C31;font-weight: bold;padding: 1px 18;width: 30%;">Qty</td>
                                <td style="font-size: 13px;color: #997C31;font-weight: bold;padding: 1px 13;width: 30%;">Price</td>
                                <td style="font-size: 13px;color: #997C31;font-weight: bold;padding: 1px 13;width: 30%;">Amount</td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($value['InvoiceProduct'] as $k => $v): ?>
                            <tr>
                                <td align="center" style="padding: 3px 0px;"><?= $v['Product']['name'] ?></td>
                                <td align="center" style="padding: 3px 0px;"><?= $v['qty'] ?> <span style="color: gray;font-size: 12px;">(<?= $v['Unit']['name'] ?>)</span></td>
                                <td align="center" style="padding: 3px 0px;"><?= $v['price'] ?></td>
                                <td align="center" style="padding: 3px 0px;"><?= number_format($v['qty']*$v['price'], 2) ?></td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                        <tfoot>
                        </tfoot>
                        </table>    
                <?php else: ?>
                    <span class="<?= ($value['pay_type'] == 'cheque')?'moneyIcon tipW':'moneyStatus';?>" original-title="<?= ucfirst($value['bank_name']).", On:".date('d-m-Y', strtotime($value['due_date']))?>">
                        <?= ($value['pay_type'] == 'cheque')?(ucfirst($value['pay_type'])):ucfirst($value['pay_type']);?>
                    </span>
                <?php endif; ?>
            </td>
            <?php $amount += $value['amount']; ?>
            <td align="center"><strong class="red"><?= ($value['amount'] < 0)?number_format(-1*($value['amount']),2):'-'?></strong></td>
            <td align="center"><strong class="green"><?= ($value['amount'] > 0)?number_format(($value['amount']),2):'-'?></strong></td>
            <td align="center"><?= number_format(-1*$amount, 2)?></td>
        </tr>
        <?php endforeach; ?>
    </tbody>
    <tfoot>
    </tfoot>
</table>
            <div class="totalAmount">
    <h4 class="floatL blue">Total : &nbsp;&nbsp;</h4>
    <h4><span class="<?= ($amount<0)?'red':'green';?>"><?= number_format(-1*$amount) ?></span><span> L.E</span></h4>
    </div>
